package org.opens.guava.utilites.eventBus.service;

import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import org.opens.guava.utilites.eventBus.base.Request;
import org.opens.guava.utilites.eventBus.base.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SaveService {

    private final static Logger LOGGER = LoggerFactory.getLogger(SaveService.class);

    private EventBus eventBus;

    public SaveService(EventBus eventBus) {
        this.eventBus = eventBus;
        eventBus.register(this);
    }

    public void save(Request request) {
        eventBus.post(request);
        LOGGER.info("save {} success", request);
    }

    @Subscribe
    public void acceptResponse(Response response) {
        LOGGER.info("从event bus中取出的响应为: {}", response);
    }

}
